package com.bachongLightNovel.system.controller;


import com.bachongLightNovel.model.pojo.system.Permission;
import com.bachongLightNovel.model.vo.system.PermissionVo;
import com.bachongLightNovel.result.Result;
import com.bachongLightNovel.system.service.SystemPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/system/permission")
@RestController
@Slf4j
public class SystemPermissionController {

    @Autowired
    private SystemPermissionService systemPermissionService;

    /**
     * 权限列表树形查询
     * @param :
     * @return Result
     * @author vermouth
     */
    @GetMapping("/getNodes")
    public Result findPage() {
        log.info("权限列表树形查询");
        List<Permission> list = systemPermissionService.findPage();
        return Result.success(list);
    }

    /**
     * 获取动态菜单权限
     * @param userId:
     * @return Result
     * @author vermouth
     */
    @GetMapping("/permissions")
    public Result getPermissions(@RequestHeader(value = "userId") Long userId) {
        log.info("获取动态菜单权限：{}",userId);
        List<PermissionVo> permissions = systemPermissionService.getPermissions(userId);
        return Result.success(permissions);
    }

    /**
     * 根据角色id查询对应的权限信息
     * @param roleId:
     * @return Result
     * @author vermouth
     */
    @GetMapping("/getPermissionsByRoleId/{roleId}")
    public Result getPermissionsByRoleId(@PathVariable Long roleId){
        log.info("根据角色id查询对应的权限信息：{}",roleId);
        List<Long> permissionIds=systemPermissionService.getPermissionIdsByRoleId(roleId);
        return Result.success(permissionIds);
    }
}
